from tkinter import *
import tkinter.messagebox #导入 messagebox 实现弹窗
import requests as rq
from bs4 import BeautifulSoup as bs
header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
data = []
picture = []
for i in range(0,100,10):
    url = 'https://maoyan.com/board/4?offset='+str(i)
    sources = rq.get(url,headers = header).text #获取网页源代码
    soup = bs(sources,'html.parser') #html.parser是解析器
    
    #根据以上分析方法得到更加快捷的方式获取网站信息
    ranks = soup.find_all('i',class_="board-index") #排名
    names = soup.find_all('p',class_="name") #电影名
    stars = soup.find_all('p',class_="star") #演员
    time = soup.find_all('p',class_="releasetime") #上映时间
    scores = soup.find_all('p',class_="score")  #评分
    pics = soup.find_all('img',class_="board-img") #获取图片
    
    for i in pics:
        pic = i['data-src'][:-16]
        picture.append(pic) #将所有图片信息存在picture
    
    for r,n,s1,t,s2 in zip(ranks,names,stars,time,scores):
        rank = r.get_text()
        name = n.get_text().strip()
        star = s1.get_text().strip()
        time = t.get_text()
        score = s2.get_text()
            
        data.append([rank,name,star,time,score])
    
g = [] #合并文本信息和图片地址
for i in range(0,len(data)):
    a = data[i]
    a.append(picture[i])
    g.append(a)

p1 = g[0:10]
p2 = g[10:20]
p3 = g[20:30]
p4 = g[30:40]
p5 = g[40:50]
p6 = g[50:60]
p7 = g[60:70]
p8 = g[70:80]
p9 = g[80:90]
p10 = g[90:100]

def b1():
    tkinter.messagebox.showinfo(title="文件1", message=p1)
def b2():
    tkinter.messagebox.showinfo(title="文件2", message=p2)
def b3():
    tkinter.messagebox.showinfo(title="文件3", message=p3)
def b4():
    tkinter.messagebox.showinfo(title="文件4", message=p4)
def b5():
    tkinter.messagebox.showinfo(title="文件5", message=p5)
def b6():
    tkinter.messagebox.showinfo(title="文件6", message=p6)
def b7():
    tkinter.messagebox.showinfo(title="文件7", message=p7)
def b8():
    tkinter.messagebox.showinfo(title="文件8", message=p8)
def b9():
    tkinter.messagebox.showinfo(title="文件9", message=p9)
def b10():
    tkinter.messagebox.showinfo(title="文件10", message=p10)
#    print(p1)
    
root = Tk()
root.title('猫眼TOP100') #弹窗的名称
root.geometry('300x350+100+200') #设置窗口 500:宽度 300：高度 +100：距离左屏幕距离 +200：距离上屏幕距离
Button(root,text='第一页',font='华文新魏',fg='blue',bg='#d3fbfb',relief=RAISED,command=b1).place(x=10,y=10,width=80,height=30)
#Button(root,text='第一名',font='华文新魏',fg='blue',bg='#d3fbfb',relief=RAISED,width=5,height=2,command=b1).pack() #Button按钮  .pack()整合窗口 RAISED凸起的'熊二'窗口
Button(root,text='第二页',font='华文新魏',relief=RAISED,command=b2).place(x=10,y=40,width=80,height=30)
Button(root,text='第三页',font='华文新魏',relief=RAISED,command=b3).place(x=10,y=70,width=80,height=30)
Button(root,text='第四页',font='华文新魏',relief=RAISED,command=b4).place(x=10,y=100,width=80,height=30)
Button(root,text='第五页',font='华文新魏',relief=RAISED,command=b5).place(x=10,y=130,width=80,height=30)
Button(root,text='第六页',font='华文新魏',relief=RAISED,command=b6).place(x=10,y=160,width=80,height=30)
Button(root,text='第七页',font='华文新魏',relief=RAISED,command=b7).place(x=10,y=190,width=80,height=30)
Button(root,text='第八页',font='华文新魏',relief=RAISED,command=b8).place(x=10,y=220,width=80,height=30)
Button(root,text='第九页',font='华文新魏',relief=RAISED,command=b9).place(x=10,y=250,width=80,height=30)
Button(root,text='第十页',font='华文新魏',relief=RAISED,command=b10).place(x=10,y=280,width=80,height=30)
root.mainloop() #调用组件的mainloop()方法，进入事件循环

